import { app, Notification, BrowserWindow, NotificationConstructorOptions} from "electron"

/**
 * 通知提醒类
 */
class notification {
    public constructor () {}

    // 执行通知
    public run (title: string, body: string) {
        // 执行通知
        this.showNotified(title, body)
        this.showDock()
    }

    // 停止通知
    public shot() {}

    // 通知方法
    private showNotified(title: string, body: string) {
        const option = {
            title: title,
            body: body,
            silent: false, 
            urgency: 'critical'
        } as NotificationConstructorOptions
        new Notification(option).show() 
    }

    private showDock() {
        // 苹果系统
        if (process.platform == 'darwin') {
            app.dock?.show()
            app.dock?.bounce("critical")
        }
        // Window 和 linux系统
        else {
            try {
                const mainWindow = BrowserWindow.getFocusedWindow() || BrowserWindow.getAllWindows()[0]
                mainWindow?.flashFrame(true)
            } catch(error) {
                console.log("Dock操作错误:", error)
            }
        }
    }
}

export default () => {
    return new notification()
}